package com.quxiu.system.service.impl;

import java.util.List;

import com.quxiu.common.core.utils.DateUtils;
import com.quxiu.system.constant.EntitySysField;
import com.quxiu.system.domain.MagicEntityMeta;
import org.springframework.stereotype.Service;
import com.quxiu.system.mapper.MagicEntityMapper;
import com.quxiu.system.domain.MagicEntity;
import com.quxiu.system.service.IMagicEntityService;

import javax.annotation.Resource;

/**
 * 数据实体Service业务层处理
 *
 * @author quxiu
 * @date 2024-06-04
 */
@Service
public class MagicEntityServiceImpl implements IMagicEntityService {
    @Resource
    private MagicEntityMapper magicEntityMapper;

    /**
     * 查询数据实体
     *
     * @param entityId 数据实体主键
     * @return 数据实体
     */
    @Override
    public MagicEntity selectMagicEntityByEntityId(Long entityId) {
        return magicEntityMapper.selectMagicEntityByEntityId(entityId);
    }

    /**
     * 查询数据实体列表
     *
     * @param magicEntity 数据实体
     * @return 数据实体
     */
    @Override
    public List<MagicEntity> selectMagicEntityList(MagicEntity magicEntity) {
        return magicEntityMapper.selectMagicEntityList(magicEntity);
    }

    /**
     * 新增数据实体
     *
     * @param magicEntity 数据实体
     * @return 结果
     */
    @Override
    public int insertMagicEntity(MagicEntity magicEntity) {
        magicEntity.setCreateTime(DateUtils.getNowDate());
        int i = magicEntityMapper.insertMagicEntity(magicEntity);
        if (i > 0){

        }
        return i;
    }

    /**
     * 修改数据实体
     *
     * @param magicEntity 数据实体
     * @return 结果
     */
    @Override
    public int updateMagicEntity(MagicEntity magicEntity) {
        magicEntity.setUpdateTime(DateUtils.getNowDate());
        return magicEntityMapper.updateMagicEntity(magicEntity);
    }

    @Override
    public boolean checkEntityNameUnique(MagicEntity magicEntity){
        int sum = magicEntityMapper.checkEntityNameUnique(magicEntity);
        return sum == 0;
    }

    @Override
    public boolean checkEntityTitleUnique(MagicEntity magicEntity){
        int sum = magicEntityMapper.checkEntityTitleUnique(magicEntity);
        return sum == 0;
    }

    /**
     * 批量删除数据实体
     *
     * @param entityIds 需要删除的数据实体主键
     * @return 结果
     */
    @Override
    public int deleteMagicEntityByEntityIds(Long[] entityIds) {
        return magicEntityMapper.deleteMagicEntityByEntityIds(entityIds);
    }

    /**
     * 删除数据实体信息
     *
     * @param entityId 数据实体主键
     * @return 结果
     */
    @Override
    public int deleteMagicEntityByEntityId(Long entityId) {
        return magicEntityMapper.deleteMagicEntityByEntityId(entityId);
    }

    @Override
    public void updateFields(Long userId, Long entityId, List<MagicEntityMeta> fields) {

    }
}
